var path = require('path');
var fs = require('fs');
var gm = require('gm').subClass({ imageMagick: true });//默认的情况下 gm使用的是另外一个图片处理程序

var app = process.app;
var config = app.get('read');


app.get('/bioscope/:path/:filename', function (req, res) {
    console.log('监听到了图片请求，请求的图片地址为:',req.params.path+'/'+req.params.filename)
    var targetDir = path.join(app.get('targetDir'),req.params.path);
    console.log(targetDir)

	var filePath = path.join(targetDir, req.params.filename);
    var defaultFilePath = path.join(app.get('targetDir'), 'img',config.default);
	fs.exists(filePath, function (exists) {
		res.sendfile(exists ? filePath : defaultFilePath);
	});
});